package com.qys.livesMall.open.mail;

import com.qys.livesMall.open.enums.EmailEnum;
import com.qys.livesMall.open.mail.config.MailConfig;
import com.qys.livesMall.open.mail.modal.MailM;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Slf4j
@Component
public class AsyncMailClient {

    @Async
    public void send(MailM m){
        try {
            //获取当前配置
            MailConfig config = MailConfig.get();
            if (config == null) {
                log.error("发送邮件失败：未找到邮件配置");
                return;
            }
            if (Objects.equals(config.getType(), EmailEnum.SES.getType())) {
                AmazonSESClient.send(config, m);
            } else {
                MailClient.sendText(m);
            }

        }catch (Exception e){
            log.error("发送邮件失败");
        }
    }
}
